<template>
  <a-card :bordered="false" class="card-area">
    <div :class="advanced ? 'search' : null">
      <!-- 搜索区域 -->
      <a-form layout="horizontal">
        <div :class="advanced ? null: 'fold'">
          <a-row>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="法人行"
                :labelCol="{span: 5}"
                :wrapperCol="{span: 16, offset: 1}">
                <a-select
                          mode="default"
                          :allowClear="true"
                          style="width: 100%"
                          @change="handleInstChange"
                          v-model="queryParams.instId">
                  <a-select-option v-for="r in instIdData" :key="r.label">{{r.label}}-{{r.value}}</a-select-option>
                </a-select>
<!--                <a-input v-if="!this.user.admin" v-model="queryParams.instId" :value="this.user.instId"
                         readonly="readonly"/>-->
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24" v-show="queryParams.instId!=''">
              <a-form-item
                label="对账场景标识"
                :labelCol="{span: 5}"
                :wrapperCol="{span: 16, offset: 1}">
                <a-input placeholder="对账场景标识" v-model="queryParams.reconSceneId"/>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :md="12" :sm="24" v-show="queryParams.instId!=''">
              <a-form-item
                label="批次日期"
                :labelCol="{span: 5}"
                :wrapperCol="{span: 18, offset: 1}">
                <a-date-picker
                  placeholder="请选择日期"
                  name="batchDate"
                  v-model="queryParams.batchDate"
                  valueFormat="YYYYMMDD"
                  format="YYYYMMDD"/>
              </a-form-item>
            </a-col>
          </a-row>
        </div>
        <div style="text-align: center;margin-bottom: 20px " v-show="queryParams.instId!=''">
          <a-button type="primary" @click="search">查询</a-button>
          <a-button style="margin-left: 8px" @click="reset">重置</a-button>
        </div>
      </a-form>
    </div>
    <div v-show="queryParams.instId!=''">

      <!--<div class="operator">-->
      <!--<a-button v-hasPermission="['reconSceneMonitor:add']" ghost type="primary" @click="add">新增</a-button>-->
      <!--</div>-->
      <!-- 表格区域 -->
      <a-table ref="TableInfo"
               :columns="columns"
               :rowKey="record => record.id"
               :dataSource="dataSource"
               :pagination="pagination"
               :loading="loading"
               :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
               :scroll="{ x: 1100 }"
               @change="handleTableChange">
        <template slot="email" slot-scope="text, record">
          <a-popover placement="topLeft">
            <template slot="content">
              <div style="width: 50px">{{text}}</div>
            </template>
            <p style="width: 50px;margin-bottom: 0">{{text}}</p>
          </a-popover>
        </template>
        <template slot="operation" slot-scope="text, record">
          <!--<a-icon v-hasPermission="['reconSceneMonitor:update']" type="setting" theme="twoTone" twoToneColor="#4a9ff5"-->
          <!--@click="editReconPath(record)" title="修改"></a-icon>&nbsp;-->
          <a-icon v-hasPermission="['reconSceneMonitor:view']" type="eye" theme="twoTone" twoToneColor="#42b983"
                  @click="view(record)" title="查看"></a-icon>
          <a-badge v-hasNoPermission="['reconSceneMonitor:view']" userStatus="warning" text="无权限"></a-badge>
          <!--<a-popconfirm title="确定停用？" @confirm="reconSceneMonitorStop(record)" okText="确定" cancelText="取消">-->
          <!--<a-icon v-hasPermission="['reconSceneMonitor:stop']" type="pause" style="color: #42b983" title="停用"/>&nbsp;&nbsp;-->
          <!--</a-popconfirm>&nbsp;-->
          <!--<a-popconfirm title="确定启用？" @confirm="reconSceneMonitorStart(record)" okText="确定" cancelText="取消">-->
          <!--<a-icon v-hasPermission="['reconSceneMonitor:start']" type="pause" style="color: #42b983" title="启用"/>&nbsp;&nbsp;-->
          <!--</a-popconfirm>&nbsp;-->
          <!--<a-popconfirm title="确定注销？" @confirm="reconSceneMonitorCancel(record)" okText="确定" cancelText="取消">-->
          <!--<a-icon v-hasPermission="['reconSceneMonitor:cancel']" type="pause" style="color: #42b983" title="注销"/>&nbsp;&nbsp;-->
          <!--</a-popconfirm>&nbsp;-->
          <!--<a-badge v-hasNoPermission="['reconSceneMonitor:update','reconSceneMonitor:view','reconSceneMonitor:stop'-->
          <!--,'reconSceneMonitor:cancel']" userStatus="warning" text="无权限"></a-badge>-->
        </template>

      </a-table>
      <!-- 查看 -->
      <ReconSceneMonitorInfo
        ref="reconSceneMonitorInfo"
        @close="handleReconSceneMonitorInfoClose"
        :reconSceneMonitorInfoVisiable="reconSceneMonitorInfo.visiable"
        :reconSceneMonitorInfoData="reconSceneMonitorInfo.data">

      </ReconSceneMonitorInfo>


    </div>
  </a-card>
</template>

<script>
  import {mapState} from "vuex"
  import ReconSceneMonitorInfo from './ReconSceneMonitorInfo'

  export default {
    name: "ReconSceneMonitor",
    components: {ReconSceneMonitorInfo},
    data() {
      return {
        advanced: false,
        reconSceneMonitorInfo: {
          visiable: false,
          data: {}
        },
        queryParams: {
          reconSceneId: '',
          batchDate: '',
          instId: ''
        },
        dataSource: [],
        sortedInfo: null,
        paginationInfo: null,
        selectedRowKeys: [],
        pagination: {
          pageSizeOptions: ['10', '20', '30', '40', '100'],
          defaultCurrent: 1,
          defaultPageSize: 10,
          showQuickJumper: true,
          showSizeChanger: true,
          showTotal: (total, range) => `显示 ${range[0]} ~ ${range[1]} 条记录，共 ${total} 条记录`
        },
        loading: false,
        instIdData: [],
      }
    },
    computed: {
      ...mapState({
        user: state => state.account.user,

      }),
      columns() {
        let {sortedInfo} = this
        sortedInfo = sortedInfo || {}
        let {filteredInfo} = this
        filteredInfo = filteredInfo || {}
        return [{
          title: '对账场景标识',
          dataIndex: 'reconSceneId',
          scopedSlots: {customRender: 'reconSceneId'}
        }, {
          title: '批次日期',
          dataIndex: 'batchDate',
          scopedSlots: {customRender: 'batchDate'},
        }, {
          title: '检查任务数量',
          dataIndex: 'checkTaskNum',
          scopedSlots: {customRender: 'checkTaskNum'},

        }, {
          title: '创建时间',
          dataIndex: 'createTime',
          scopedSlots: {customRender: 'createTime'},
        }, {
          title: '操作',
          dataIndex: 'operation',
          fixed: 'right',
          scopedSlots: {customRender: 'operation'}
        }]
      }
    },
    mounted() {
      this.$get('admin/upmporg/getInstList').then((r) => {
        this.instIdData = r.data
      })
    },
    methods: {
      onSelectChange(selectedRowKeys) {   //接收数组，存放到前面定义的数组中
        this.selectedRowKeys = selectedRowKeys
      },

      handleReconSceneMonitorInfoClose() {
        this.reconSceneMonitorInfo.visiable = false
      },
      view(record) {
        this.reconSceneMonitorInfo.data = record
        this.$refs.reconSceneMonitorInfo.setReconSceneMonitorFormValues(record)
        this.reconSceneMonitorInfo.visiable = true
      },

      handleInstChange(value) {
        this.queryParams.instId = value;
        if (value != "") {
          let params = {}
          params.instId = value;
          this.$get('/admin/csmc/recon-scene-monitor', {...params}).then((r) => {

            this.dataSource = r.data.rows;
            this.search();
          })
        }
      },
      search() {
        let {sortedInfo, filteredInfo} = this
        let sortField, sortOrder
        // 获取当前列的排序和列的过滤规则
        if (sortedInfo) {
          sortField = sortedInfo.field
          sortOrder = sortedInfo.order
        }
        let params = {}
        params.instId = this.queryParams.instId
        params.reconSceneId = this.queryParams.reconSceneId
        params.batchDate = this.queryParams.batchDate


        this.fetch({
          sortField: sortField,
          sortOrder: sortOrder,
          ...params,
          ...filteredInfo
        })
      },

      reset() {
        // 取消选中
        this.selectedRowKeys = []
        // 重置分页
        this.$refs.TableInfo.pagination.current = this.pagination.defaultCurrent
        if (this.paginationInfo) {
          this.paginationInfo.current = this.pagination.defaultCurrent
          this.paginationInfo.pageSize = this.pagination.defaultPageSize
        }
        // 重置列排序规则
        this.sortedInfo = null
        // 重置查询参数
        this.queryParams = {}
        // // 清空时间选择
        // this.$refs.createTime.reset()
        this.fetch()
      },

      handleTableChange(pagination, filters, sorter) {
        // 将这三个参数赋值给Vue data，用于后续使用
        this.paginationInfo = pagination
        this.filteredInfo = filters
        this.sortedInfo = sorter
        // this.userInfo.visiable = false
        this.fetch({
          sortField: sorter.field,
          sortOrder: sorter.order,
          ...this.queryParams,
          ...filters
        })
      },

      fetch(params = {}) {
        this.loading = true
        if (this.paginationInfo) {
          // 如果分页信息不为空，则设置表格当前第几页，每页条数，并设置查询分页参数
          this.$refs.TableInfo.pagination.current = this.paginationInfo.current
          this.$refs.TableInfo.pagination.pageSize = this.paginationInfo.pageSize
          params.pageSize = this.paginationInfo.pageSize
          params.pageNum = this.paginationInfo.current
        } else {
          // 如果分页信息为空，则设置为默认值
          params.pageSize = this.pagination.defaultPageSize
          params.pageNum = this.pagination.defaultCurrent
        }
        this.$get('/admin/csmc/recon-scene-monitor', {
          ...params
        }).then((r) => {
          let data = r.data
          const pagination = {...this.pagination}
          pagination.total = data.total
          this.dataSource = data.rows
          this.pagination = pagination
          this.loading = false
        })
      }
    },

  }
</script>

<style scoped>

</style>
